//
//  PopoverViewController.m
//  evidenceGather
//
//  Created by 王继伟 on 13-9-8.
//  Copyright (c) 2013年 无. All rights reserved.
//

#import "PopoverViewController.h"
#import "DefTableViewCell.h"
#import "MDGather.h"
#import "GatherResult.h"

@interface PopoverViewController ()

@end

@implementation PopoverViewController

@synthesize mdGather;
@synthesize gatherCodeVOs;


-(id) initViewWithCode:(NSString *)projCode probClsCode :(NSString *)probClsCode prvcode :(NSString *)prvcode loginUser :(NSString *)loginUser{
    
    [super viewDidLoad];
    self.title = @"记录选择";
    if(mdGather==nil){
        mdGather =[[MDGather alloc] init];
    }
    
    NSMutableDictionary *gatherCodeDict=[mdGather qryGatherRecourdByPk:projCode pccode:probClsCode prvcode:prvcode loginUser:loginUser ];
    if(gatherCodeDict!=nil){
        NSArray *tempGatherVos=[gatherCodeDict allValues];
        gatherCodeVOs =[[NSMutableArray alloc] init];
        for(int i=0;i<[gatherCodeDict count];i++){
            MDGather *gatherVO =[tempGatherVos objectAtIndex:i];
            [gatherCodeVOs addObject:gatherVO];
        }
    }
    return self;
    
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(gatherCodeVOs!=nil){
        return [gatherCodeVOs count];
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    int index=indexPath.row;
    GatherResult *gatherVO=[gatherCodeVOs objectAtIndex:index];
    
    NSString *cellText = gatherVO.gathercode; 
    DefTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellText];
    cell.cellCode=gatherVO.gathercode; 
    
    if(cell == nil)
    {
        cell = [[[DefTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellText] autorelease];
    }
    cell.textLabel.text = cellText;
    return cell;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
    int index=indexPath.row;
    GatherResult *gatherVO=[gatherCodeVOs objectAtIndex:index];
    [self.delegate afterCellSelected:gatherVO.gathercode cellName:@"" tag:3];
}

@end
